package com.lifeng.patterns.templatemethod;

import java.util.Map;

/**
 * Created by lifeng on 2019/10/16.
 * 调用支付宝
 */
public class AliPayReromeCall extends AbstractRemoteCall{
    @Override
    protected Object getBean(Map<String, Object> reqMap) {
        AlipayDto alipayDto = new AlipayDto();
        alipayDto.setpId((String) reqMap.get("merid"));
        alipayDto.setOrderNo((String) reqMap.get("orderno"));
        alipayDto.setAmt((Long) reqMap.get("amt"));
        alipayDto.setBody((String) reqMap.get("body"));
        return alipayDto;
    }

    @Override
    public Object executeBiz(Object obj) throws Exception {
        //TODO 模拟调用远程
        AlipayDto alipayDto = new AlipayDto();
        alipayDto.setRetCode("200");
        alipayDto.setRetMsg("交易成功");
        alipayDto.setOrderNo("1111111111");
        return alipayDto;
    }

    @Override
    public Map<String, Object> getRspMap(Object ret, Map<String, Object> rspMap) throws Exception {
        AlipayDto alipayDto = (AlipayDto) ret;
        rspMap.put("orderno",alipayDto.getOrderNo());
        rspMap.put("rspcode",alipayDto.getRetCode());
        rspMap.put("rspmsg",alipayDto.getRetMsg());
        return rspMap;
    }
}
